<%@page import="databaseLayer.RecordLookUp" %>
<%@page import="databaseLayer.UserLookUp" %>
<%@page import="userBean.*" %>
<%@page import="databaseLayer.MoviesLookUp" %>
<%@page import="userBean.PurchaseRecord" %>
<%@page import="java.text.SimpleDateFormat" %>
<%@page import="java.util.Date" %>
<%@page import="java.util.GregorianCalendar" %>

<% PurchaseRecord[] record = RecordLookUp.getPurchaseRecord((String)request.getAttribute("userName"));%>
<h3>Account Information</h3>
<table class="indexTable">
    <tr class="odd">
        <td>Login ID</td>
        <td>${userName}</td>
    </tr>
    <tr class="even">
        <td>Name</td>
        <td>${userRealName}</td>
    </tr>
    <tr class="odd">
        <td>LoyaltyPoint</td>
        <td><%= UserLookUp.getPoint((String)request.getAttribute("userName")) %></td>
    </tr>
</table>
<br />
<br />
<table class="indexTable">
    <h3>Purchase Record</h3>
    <tr class ="odd">
        <td>Transaction Time</td>
        <td>Movie Name</td>
        <td>Number of Tickets</td>
        <td>Total Price</td>
        <td>Used Loyalty Point</td>
        <td>State</td>
        <td>&nbsp;</td>
    </tr>
    <% for (int i = 0; record != null && i < record.length; i++) {%>
    <tr class="<%= i % 2 == 0 ? "even" : "odd"%>">
        <td> <%= record[i].getPurchaseTime()%></td>
        <td> <%= record[i].getMovieName()%></td>
        <td> <%= record[i].getAmount()%></td>
        <td> <%= record[i].getTotalPrice()%></td>
        <td> <%= record[i].getUsedLoyaltyPoint()%></td>
        <td> <%= record[i].getState()%></td>
        <td> 
            <% 
            Date currentTime = new Date();
            
            GregorianCalendar tempCal = new GregorianCalendar();
            tempCal.setTime(currentTime);
            tempCal.add(GregorianCalendar.MINUTE, 180);
            currentTime=tempCal.getTime();
            SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy'/'MM'/'dd HH:mm:ss z");
            Date inputtedStartTime = dateFormatter.parse(MoviesLookUp.getMovieSlotStartTime(record[i].getSlotID()));
            if(record[i].getUsedLoyaltyPoint()==0 && record[i].getState().equals("Paid") && currentTime.before(inputtedStartTime)){ %>
            <form action="Refund.do" method="post">
                <input type="hidden" name="recordID" value="<%= record[i].getRecordID() %>">
                <input type="hidden" name="action" value="refund">
                <input type="submit" value="Refund">
            </form>
            <% } %>
        </td>
    </tr>
    <% }%>
</table>
<br />